<?php


namespace App\Http\ModelDao\Job;


use App\Config\QueueConfig;
use App\Http\Library\Queue;

class PfsHeadAddclassincrementDao
{

    /**
     * 响应数据格式转换
     *
     * @param $result
     *
     * @return array
     */
    public static function result($result)
    {
        $data = [];
        foreach ($result as $val) {
            $data[$val->classId] = $val;
        }
        return $data;
    }


    /**
     * 招行-售/退课汇总信息同步-获取需要同步的classList结构
     *
     * @param $data
     *
     * @return array
     */
    public static function classList($data, &$createDate, &$statisticDate)
    {
        $arr = [];
        foreach ($data['list'] as $val) {
            if (empty($createDate)) {
                $createDate = $val->create_date;
            }
            if (empty($statisticDate)) {
                $statisticDate = $val->statistic_date;
            }
            /*检查是否存在不是同一天的记录*/
            if ($createDate !== $val->create_date) {
                throw new \Exception('数仓-当日推送缴退费汇总表PayClassList（按班级汇总）,存在差异日期!!!');
            }
            if ($statisticDate !== $val->statistic_date) {
                throw new \Exception('数仓-当日推送缴退费汇总表PayClassList（按班级汇总）,存在差异日期!!!');
            }
            /*注册班级余额刷新任务*/
            Queue::clock([
                'class_id'  => $val->class_id,
                'pfs_dw_id' => $data['pfs_dw_id'],
                /*取汇总记录创建时间,跟班级信息有区别*/
                'date'      => $val->create_date,
            ], 60, QueueConfig::CLASS_AMT_REFRESH);
            $arr[] = [
                /*班级编号，同一机构下确保唯一*/
                'classId'              => $val->class_id,
                /*T-1日缴费笔数*/
                'payNum'               => $val->pay_num,
                /*T-1日缴费金额*/
                'payAmt'               => $val->pay_amt,
                /*T-1日缴费手续费*/
                'payFee'               => $val->pay_fee,
                /*T-1日退费笔数*/
                'refundNum'            => $val->refund_num,
                /*T-1日退费金额*/
                'refundAmt'            => $val->refund_amt,
                /*T-1日退费对应的手续费*/
                'refundFee'            => $val->refund_fee,
                /*总报名课时*/
                'totalEnrollClassHour' => $val->total_enroll_class_hour,
                /*总退课课时*/
                'totalDropClassHour'   => $val->total_drop_class_hour,
                /*截止T-1缴费总笔数*/
                'totalPayNum'          => $val->total_pay_num,
                /*截止T-1总缴费金额*/
                'totalPayAmt'          => $val->total_pay_amt,
                /*截止T-1缴费总手续费*/
                'totalPayFee'          => $val->total_pay_fee,
                /*截止T-1退费总笔数*/
                'totalRefundNum'       => $val->total_refund_num,
                /*截止T-1总退费金额*/
                'totalRefundAmt'       => $val->total_refund_amt,
                /*截止T-1退费总手续费*/
                'totalRefundFee'       => $val->total_refund_fee,
            ];
        }
        return $arr;
    }


}





/**
 * PfsHeadAddclassincrementDao.php
 *
 * 说明:
 *
 * 修改历史
 * ----------------------------------------
 * 2021/6/7 15:13:00   操作:创建
 **/
